var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"), common_Js = require("../../../../component/common.js")
import Dialog from '../../../../component/vant/dialog/dialog';
import Toast from '../../../../component/vant/toast/toast';


Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    netWork: false,
    isLoading: true,
    activeDetail:{},
    activeId:0,
    isLogin:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('活动详情参数',options)
    
    if(options.q){
      var q = decodeURIComponent(options.q) // 获取到二维码原始链接内容
      const scancode_time = parseInt(options.scancode_time) // 获取用户扫码时间 UNIX 时间戳
      
      q = "?" + q.split("?")[1];
      this.data.query = q;
      console.log('q',q)
      options = common_Js.getQueryVariable(q);
      console.log('options',options)
      var id = parseInt(options.id) 
      this.data.activeId = id
    }else{
      if(options.id){
        this.data.activeId = parseInt(options.id)
      }
    }
    this.data.isLogin = app.getStorageSync('isLogin');
    this.setData({
      isLogin: app.getStorageSync('isLogin')
    })
    this.onHttpInit();
  },
  onShow(){
  },

  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/active/detail', {
      active_id: that.data.activeId
    }, function (res) {
      console.log("活动详情数据", res)
      if (res.data.code == 0) {
        that.data.activeDetail = res.data.data,
        that.setData({
          activeDetail:res.data.data,
          hasData: true,
        })
      }else{
        that.setData({
          hasData: false,
        })
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  goSign(e){
    this.data.isLogin = app.getStorageSync('isLogin');
    this.setData({
      isLogin: app.getStorageSync('isLogin')
    })
    console.log('this.data.isLogin', this.data.isLogin)
    if(this.data.isLogin == 1){
      wx.navigateTo({
        url: '../sign/index?id=' + this.data.activeId,
      })
    }else{
      wx.navigateTo({
        url: '/pages/login/index',
      })
    }

  },
  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this;
    return {
      title:  that.data.activeDetail.activeTitle ,
      path: '/pagesProperty/pages/active/detail/index?id='+ that.data.activeId,
      success: function (res) {
        console.log(res, "转发成功")
      },
      fail: function (res) {
        console.log(res, "转发失败")
      }
    }
  },  
})